package com.wang.interview.threads;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author: wang
 * @date: 2021/7/23 13:48
 * @description: // 减计数
 */
class CountDownLatchTest {
//    static CountDownLatch countDownLatch = new CountDownLatch(6);

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        new Thread(()->{
            countDownLatch.countDown();
            System.out.println("==>:"+Thread.currentThread().getName());
        },"A").start();
        new Thread(()->{
            countDownLatch.countDown();
            System.out.println("==>:"+Thread.currentThread().getName());
        },"B").start();
        new Thread(()->{
            countDownLatch.countDown();
            System.out.println("==>:"+Thread.currentThread().getName());
        },"C").start();
        new Thread(()->{
            countDownLatch.countDown();
            System.out.println("==>:"+Thread.currentThread().getName());
        },"D").start();
        new Thread(()->{
            countDownLatch.countDown(); // 门锁减一
            System.out.println("==>:"+Thread.currentThread().getName());
        },"E").start();
        countDownLatch.await(2, TimeUnit.SECONDS); // 过时不候，不带参数则在数量为0之前阻塞
        System.out.println("close");
    }
}
